package com.zkhz.base.security.util;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * @author ZhiYong
 * @ClassName MyBCryptPasswordEncoder.java
 * @Description 增强BCryptPasswordEncoder
 * @createTime 2022/02/27 21:31:00
 */
@Component
public class MyPasswordEncoder extends BCryptPasswordEncoder {

    @Override
    public String encode(CharSequence rawPassword) {
        // 可做增强
        return super.encode(rawPassword);
    }

    /**
     * 自定义BCryptPasswordEncoder密码验证
     * 增强原有的验证，比如前端传来的是某种加密规则的数据，需要提前进行解密后再做BCryptPasswordEncoder密文验证
     * @param rawPassword 原文
     * @param encodedPassword 密文
     * @return
     */
    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
//        String pwd = decodedLoginPassword((String) rawPassword);
        // 可做增强
        return super.matches(rawPassword, encodedPassword);
    }

}
